package com.junjie.checkin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.junjie.checkin.entity.Enum.ActivityStatusEnum;
import com.junjie.checkin.entity.Enum.ActivityTypeEnum;
import com.junjie.checkin.entity.TActivity;
import com.junjie.checkin.request.activity.ActivityPageRequest;
import com.junjie.checkin.request.activity.ActivityParticipationRequest;
import com.junjie.checkin.request.activity.ActivityRequest;
import com.junjie.checkin.request.activity.RegistrationListPageRequest;
import com.junjie.checkin.response.admin.ActivityParticipationResponse;
import com.junjie.checkin.response.admin.RegistrationListPageResponse;
import com.junjie.checkin.response.front.ActivityFrontResponse;
import com.junjie.checkin.response.admin.ActivityResponse;
import com.junjie.checkin.response.admin.RecentActivitiesResponse;
import com.junjie.checkin.response.front.UserActivityHistoryResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author 洪浚杰
 * @description
 * @date 2025/6/9 13:23
 */
@Mapper
public interface ActivityMapper extends BaseMapper<TActivity> {

    /**
     * 分页查询活动
     * @param request 请求参数
     * @return 分页结果
     */
    Page<ActivityResponse> pageQueryWithParticipantCount(ActivityPageRequest request);


//    /**
//     * h5端分页查询活动
//     * @param activityPageRequest
//     * @return
//     */
//    Page<ActivityResponse> pageQuery(ActivityPageRequest activityPageRequest);

    Page<UserActivityHistoryResponse> pageQueryUserParticipatedActivities(@Param("userId") Integer userId,
                                                                          @Param("title") String title,
                                                                          @Param("type") String type,
                                                                          @Param("status") String status);


    Page<ActivityFrontResponse> pageQueryWithParticipantCountAndParticipation(
            @Param("title") String title,
            @Param("type") String type,
            @Param("status") String status,
            @Param("userId") Integer userId
    );

    /**
     * 根据id查询活动
     * @param
     * @return
     */
    int updateId(ActivityRequest activityRequest);


    /**
     * 修改活动状态
     * @param id 修改的ID
     * @param status 修改的状态
     * @return 修改成功返回1，失败返回0
     */
    @Update("update t_activity set status=#{status} where id = #{id}")
    public int updateStatus(int id,String status);

    /**
     * 根据条件查询活动数量
     * @param map
     * @return
     */
    Integer countEffectiveByMap(Map map);

    /**
     * 根据条件查询学生数量
     * @param map
     * @return
     */
    Integer countStudentsByMap(Map map);


    /**
     * 查询所有活动数量
     * @return
     */
    Integer countByMap();

    /**
     * 查询最新活动
     * @param limit
     * @return
     */

    List<RecentActivitiesResponse> selectLatestActivities(int limit);

    /**
     * 查询报名列表
     * @param request
     * @return
     */
    Page<RegistrationListPageResponse> getRegistrationList(RegistrationListPageRequest request);

    /**
     * 定时判断活动是否开始
     */
    void judgmentBegins();

    /**
     * 定时判断活动是否结束
     */
    void judgmentEnds();

    /**
     * 定时修改签到状态
     */
    void modifyCheckInStatus();


    /**
     * 查询用户报名的活动
     * @param request
     * @return
     */
    Page<ActivityParticipationResponse> getJoinPageActivities(ActivityParticipationRequest request);


}
